import React,{useState, useEffect} from 'react'

export default function useHook(n) {
    const [num, setNum] = useState(n)
    let timer 
    useEffect(() => {
        if(!num){
            clearTimeout(timer) 
            timer = null
        } else{
            timer = setTimeout(() => {
                setNum((num) => num - 1)
            }, 1000)
        }
        return () => {
            clearTimeout(timer) 
            timer = null
        }
    }, [num])
    return num
}
